package jdk8;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author oldliu
 * @since 1.0
 */
public class BAnkTest {
    public static void main(String[] args) {
        List<Bank> banks = Arrays.asList(new Bank("1", "liu1", "hefei", Math.random() * 1000), new Bank("2", "liu2",
                "beijing", Math.random() * 1000), new Bank("3", "liu3", "hefei", Math.random() * 1000), new Bank("3",
                "老刘", "anqing", Math.random() * 1000), new Bank("4", "老马", "hefei", Math.random() * 1000), new Bank(
                        "5", "小宋", "anqing", Math.random() * 1000), new Bank("6", "老吴", "hefei",
                Math.random() * 1000), new Bank("7", "小张", "huaibei", Math.random() * 1000));
        //1：输出
        banks.forEach(System.out::println);
        //找出hefei的账号，放入一个List
        System.out.println(">>>>>>>hefei>>>>>>>>>>>");
        List<Bank> l2 = banks.stream().filter(x -> {
            return x.getCity().equals("hefei");
        }).collect(Collectors.toList());
        l2.forEach(System.out::println);
        System.out.println("#####统计各个城市的账号信息#####");
        //Map<String,List<Bank> )
        Map<String, List<Bank>> map = banks.stream().collect(Collectors.groupingBy(Bank::getCity,
                Collectors.toList()));
        map.forEach((a,b)->{
            System.out.println(a+"<<<"+b);
        });
        System.out.println("####各个城市钱最多的账户");
    }
}
